package org.example.brave.http;

import brave.Span;
import brave.propagation.Propagation;

/**
 * Marks an interface for use in {@link HttpClientHandler#handleSend(HttpClientRequest)}. This gives
 * a standard type to consider when parsing an outgoing context.
 *
 * @see HttpClientResponse
 * @since 5.7
 */
public abstract class HttpClientRequest extends HttpRequest {
    static final Propagation.RemoteSetter<HttpClientRequest> SETTER = new Propagation.RemoteSetter<HttpClientRequest>() {
        @Override public Span.Kind spanKind() {
            return Span.Kind.CLIENT;
        }

        @Override public void put(HttpClientRequest request, String key, String value) {
            request.header(key, value);
        }

        @Override public String toString() {
            return "HttpClientRequest::header";
        }
    };

    @Override public final Span.Kind spanKind() {
        return Span.Kind.CLIENT;
    }

    /**
     * Sets a request header with the indicated name. {@code null} values are unsupported.
     *
     * <p>This is only used when {@link TraceContext.Injector#inject(TraceContext, Object) injecting}
     * a trace context as internally implemented by {@link HttpClientHandler}. Calls during sampling or
     * parsing are invalid and may be ignored by instrumentation.
     *
     * @see #SETTER
     * @since 5.7
     */
    public abstract void header(String name, String value);
}
